package org.myOrg.spetrum.testSpectrum;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.myOrg.spetrum.combination.Tuple;
import org.myOrg.spetrum.combination.TupleImplement;
import org.myOrg.spetrum.spectrumStruct.Spectrum;
import org.myOrg.spetrum.spectrumStruct.SpectrumFactory;
import org.myOrg.spetrum.spectrumStruct.SpetrumAnalyseBase;
import org.myOrg.spetrum.testObject.TestCase;
import org.myOrg.spetrum.testObject.TestCaseImplement;
import org.myOrg.spetrum.testObject.TestSuite;
import org.myOrg.spetrum.testObject.TestSuiteImplement;
import org.myOrg.spetrum.testRun.TestRun;
import org.myOrg.spetrum.testRun.TestRunBugMode;

public class SpectrumTestBase {

	protected TestSuite rights;
	protected TestSuite wrongs;
	protected int[] param;
	protected List<Tuple> bugMode;
	protected TestRun run;
	protected Spectrum spetrum;

	public SpectrumTestBase() {
		super();
	}

	@Test
	public void test() {
	
		spetrum = SpectrumFactory.generateSpectrum(SpectrumFactory.GREEDY);
		spetrum.setInput(param, wrongs, rights);
		spetrum.setRun(run);
		assertEquals(15, ((SpetrumAnalyseBase)spetrum).getTupleManager().size());
		spetrum.run();
		assertEquals(2, spetrum.getBugs().size());
	}

	@Before
	public void setup() {
		rights = new TestSuiteImplement();
		wrongs = new TestSuiteImplement();
		bugMode = new ArrayList<Tuple>();
		param = new int[4];
	
		TestCase testCase1 = new TestCaseImplement();
		int[] data1 = { 3, 5, 4, 6 };
		((TestCaseImplement) testCase1).setTestCase(data1);
		TestCase testCase2 = new TestCaseImplement();
		int[] data2 = { 2, 4, 3, 5 };
		TestCase testCase3 = new TestCaseImplement();
		int[] data3 = { 2, 4, 2, 5 };
		((TestCaseImplement) testCase2).setTestCase(data2);
		((TestCaseImplement) testCase3).setTestCase(data3);
	
		rights.addTest(testCase1);
		wrongs.addTest(testCase2);
		wrongs.addTest(testCase3);
	
		Tuple bug = new TupleImplement(2);
		bug.set(0, 0, 2);
		bug.set(1, 2, 3);
		bugMode.add(bug);
		Tuple bug2 = new TupleImplement(2);
		bug2.set(0, 0, 2);
		bug2.set(1, 1, 4);
		bugMode.add(bug2);
	
		run = new TestRunBugMode(bugMode);
		
		for(int i = 0; i< 4; i++){
			param[i] = 7;
		}
	}

	@After
	public void tearDown() {
		TestSuite generateTestCases =spetrum.getGenerateTestCases();
		for (int i = 0; i < generateTestCases.getTestCaseNum(); i++) {
			TestCase thiscase = generateTestCases.getAt(i);
			System.out.println(thiscase.getStringOfTest() + " "
					+ thiscase.testDescription());
		}
	}

}